<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?>

<div class="middle padtop10 myclear">
	<div class="page-content">
			<!-- bread crumb -->
			<p id="bread-crumb">
				<a href="<?php echo site_url();?>">
					<?php echo $lang['home']?>
				</a>
				<a href="<?php echo site_url('budget/agency/?gid='.$groupid);?>">
					<?php echo $lang['agency']?>
				</a>
				<?php echo $uname;?>
			</p><!-- end bread crumb -->
			
			<table width="100%" class="marbottom10"  border="0" cellpadding="0" cellspacing="0">
				<tr>
					<td width="50%">
						<h2 class="title text-666">
							<?php echo $lang['financial']?>
						</h2>
					</td>
				</tr>
			</table>
			
			<div class="payment-total-info" align="right">
				<table cellpadding="0" cellspacing="0" border="0">
					<tr>
						<td class="text-666 text-right padright10" width="220">
							<?php echo $lang['title_help_balance'];?>
						</td>
						
						<td class="text-666 text-right padright10" width="220">
							<?php echo $lang['title_help_promotions'];?>
						</td>
						
						<td class="text-666 text-right padright10" width="210">
							<?php echo $lang['title_help_overdraft'];?>
						</td>
						
						<td class="text-666 text-right padright10" width="220">
							<?php echo $lang['title_help_money_use'];?>
						</td>
					</tr>
					
					<tr>
						<td class="text-right padright10" >
							<p class="payment-total-info-value">
								<b><?php echo number_format($info->balance);?></b>
							</p>
						</td>
						
						<td class="text-right padright10" >
							<p class="payment-total-info-value">
								<b><?php echo number_format($info->promotions);?></b>
							</p>
						</td>
						
						<td class="text-right padright10">
							<p class="payment-total-info-value">
								<b><?php echo number_format($info->overdraft);?></b>
							</p>
						</td>
						
						<td class="text-right padright10">
							<p class="payment-total-info-value">
								<b><?php echo number_format($info->expensed);?></b>
							</p>
						</td>
					</tr>
				</table>
			</div>
			<br /><br />
			<div class="payment-listbox">
				<table cellpadding="0" cellspacing="0" border="0">
					<tr>
						<td class="ver-middle padright5 text-666 bold">
							<?php echo $lang['offer']?>
						</td>
						<td class="padleft3 ver-middle padright20 text-666 bold">
							<select style="width:150px" class="payment-by-type" id="pay-type">
								<option value="-1" <?php if($type == -1) echo 'selected="selected"';?>><?php echo $lang['all']?></option>
								<option value="0" <?php if($type == 0) echo 'selected="selected"';?>><?php echo $lang['recharge']?></option>
								<option value="1" <?php if($type == 1) echo 'selected="selected"';?>><?php echo $lang['deductione']?></option>
							</select>
						</td>
						<td class="ver-middle padright5 text-666 bold">
							<?php echo $lang['status']?>
						</td>
						<td class="padleft3 ver-middle padright20 text-666 bold">
							<select style="width:150px" class="payment-by-type" id="pay-status">
								<option value="-1" <?php if($status == -1) echo 'selected="selected"';?>><?php echo $lang['all']?></option>
								<option value="1" <?php if($status == 1) echo 'selected="selected"';?>><?php echo $lang['success']?></option>
								<option value="0" <?php if($status == 0) echo 'selected="selected"';?>><?php echo $lang['not_success']?></option>
							</select>
						</td>
						<td style="padding-left:15px">
							<b class="ver-middle marright5"><?php echo $lang['date']?>: </b>
							<input type="text" id="slDate" style="width:150px" value="<?php echo $startdate.' / '.$enddate;?>" class="payment-by-type" />
						</td>
						<td style="padding-left:15px">
							<input type="button" value="<?php echo $lang['apply'];?>" onclick="filterLogs();" />
						</td>
					</tr>
				</table>
			</div>			
			<table class="martop5 tbl-list tb-pad5" width="100%" cellpadding="0" cellspacing="0" border="1">
				<tr>
					<td class="td-label text-666 bold" width="50">
						<span class="padleft3"><?php echo $lang['date']?></span>
					</td>
					
					<td class="td-label text-666 bold">
						<span class="padright3"><?php echo $lang['transaction_code']?></span>
					</td>
					
					<td class="td-label bold text-666">
						<span class="padleft3"><?php echo $lang['content']?></span>
					</td>
					
					<td class="td-label bold text-666" width="80">
						<span class="padleft3"><?php echo $lang['payment_type']?></span>
					</td>
					
					<td class="td-label bold text-666" width="80">
						<span class="padleft3"><?php echo $lang['recieves_link_money']?></span>
					</td>
					
					<td class="td-label bold text-666 text-right">
						<span class="padright3"><?php echo $lang['recharge_money']?></span>
					</td>
					
					<td class="td-label bold text-666 text-right">
						<span class="padright3"><?php echo $lang['deductione_money']?></span>
					</td>
					
					<td class="td-label bold text-666 text-right">
						<span class="padright3"><?php echo $lang['account_balance']?></span>
					</td>
					
					<td class="td-label bold text-666 text-right">
						<span class="padright3"><?php echo $lang['account_promotion']?></span>
					</td>
					
					<td class="td-label bold text-666 text-right">
						<span class="padright3"><?php echo $lang['status']?></span>
					</td>
				</tr>
				
				<?php 
				$sum_money_add = 0;
				$sum_money_sub = 0;
				//$sum_balance = 0;
				//$sum_promotion = 0;
				foreach($items as $paid)
				{
					if ($paid['status'] == 1)
					{
						if($paid['type'] == 0) $sum_money_add += (int)$paid['money'];
						else $sum_money_sub += (int)$paid['money'];
					}
					//$sum_balance += $paid['currentbalance'];
					//$sum_promotion += $paid['currentpromotion'];
				?>
				
				<tr>
					<td>
						<?php echo $paid['payment_time'];?>
					</td>
					
					<td>
						<a href="<?php echo site_url('logs/check_soha/?code='.$paid['payment_key']);?>" target="_blank" title="Check Soha">
							<?php echo $paid['payment_key'];?>
						</a>
					</td>
					
					<td>
						<?php echo $paid['message'];?>
					</td>
					
					<td>
						<?php echo $paid['typepay'];?>
					</td>
					
					<td>
						<?php echo $paid['linkmoney'];?>
					</td>
					
					<td style="text-align:right">
						<?php if($paid['type'] == 0) echo '+'.number_format($paid['money']);?>
					</td>
					
					<td style="text-align:right">
						<?php
						if($paid['type'] == 1)
						{
							echo '<a href="'.site_url('budget/paidView/?key='.$paid['payment_key'].'&uid='.$paid['user_id']).'" target="_blank">';
							echo '-'.number_format($paid['money']);
							echo '</a>';
						}
						?>
					</td>
					
					<td style="text-align:right">
						<?php echo number_format($paid['currentbalance']);?>
					</td>
					
					<td style="text-align:right">
						<?php echo number_format($paid['currentpromotion']);?>
					</td>
					
					<td style="text-align:center">
						<?php if ($paid['status'] == 1){?>
						<img src="/images/completed.png" border="0" title="Success" />
						<?php } else {?>
						<img src="/images/imgwait.png" border="0" title="Waiting" />
						<?php }?>
					</td>
				</tr>
				
				<?php }?>
				
				<tr>
					<td colspan="5" class="td-label" style="text-align:right">
						<b><?php echo $lang['sum'];?>:</b>
					</td>
					<td class="td-label" style="text-align:right">
						<b><?php echo number_format($sum_money_add);?></b>
					</td>
					<td class="td-label" style="text-align:right">
						<b><?php echo number_format($sum_money_sub);?></b>
					</td>
					<td class="td-label" style="text-align:right">
						<b><?php //echo number_format($sum_balance);?></b>
					</td>
					<td class="td-label" style="text-align:right">
						<b><?php //echo number_format($sum_promotion);?></b>
					</td>
					<td class="td-label">&nbsp;</td>
				</tr>
				
			</table>
			
			<!-- paging -->
			<div class="myclear martop20">
				<div class="brv-paging-left">
					<table class="tbl-list brv-paging" border="1">
						<tr>
							<td class="brv-paging-name">
								<?php echo 'Trang '. $page.' ['.$totalPage.']'?>
							</td>
							
							<td class="brv-paging-pre-next">
								<img class="brv-img-pre" alt="previous" src="/images/imgpre.gif" onclick="goPage(<?php echo $page > 1 ? $page - 1 : $page;?>)" />
								<img class="brv-img-next" alt="next" src="/images/imgnext.gif" onclick="goPage(<?php echo $page < $totalPage ? $page + 1 : $page;?>)" />
							</td>
							<td class="brv-paging-pre-next">
								<select name="lstLimit" id="lstLimit" onchange="filterLogs();">
									<?php $option = array(20, 50, 100, -1); foreach ($option as $item){?>
									<option value="<?php echo $item;?>" <?php if($limit == $item) echo 'selected="selected"';?>>
										<?php echo $item == -1 ? 'All' : $item;?>
									</option>
									<?php }?>
								</select>&nbsp; <?php echo $lang['items_in_page'];?>
							</td>
						</tr>
					</table>
				</div>
				<!-- important. fix for ie 6. Don't remove -->
				<!--[if IE 6]><br class="clearboth" /><![endif]-->
			</div>
			<!-- end paging -->
			
			<br /><br />
		</div> <!-- end colum right -->
		
		<div id="toannh-tooltip" >
			<p class="myclear">
				<img alt="" id="toannh-tooltip-arrow" src="/images/toannhtooltiparrow.gif" />
			</p>
			<div id="toannh-tooltip-inner" >
				<p id="toannh-tooltip-title"></p>
				<div id="toannh-tooltip-body" class="myclear"></div>
				<p class="ok-box myclear">
					<img alt="" src="/images/okbtn.gif" onclick="removeToannh_Tooltip();" />
				</p>
			</div>
		</div>
		
</div>
</div>

<script language="javascript">
	function filterLogs()
	{
		var type = $('#pay-type').val();
		var status = $('#pay-status').val();
		var limit = $('#lstLimit').val();
		var fd = $('#slDate').val();
		fd = fd.split(' / ');
		window.location.href = '<?php echo site_url('budget/user/?u='.$uname.'&uid='.$uid.'&gid='.$groupid);?>&type='+type+'&status='+status+'&fd='+fd[0]+'&td='+fd[1]+'&limit='+limit;
	}
	function goPage(strVal)
	{
		var type = $('#pay-type').val();
		var status = $('#pay-status').val();
		var limit = $('#lstLimit').val();
		var fd = $('#slDate').val();
		fd = fd.split(' / ');
		window.location.href = '<?php echo site_url('budget/user/?u='.$uname.'&uid='.$uid.'&gid='.$groupid);?>&type='+type+'&status='+status+'&fd='+fd[0]+'&td='+fd[1]+'&limit='+limit+'&page='+strVal;
	}
	$('#slDate').DatePicker({
		format:'Y-m-d',
		date: ['<?php echo $startdate;?>', '<?php echo $enddate;?>'],
		current: '<?php echo date('Y-m-d');?>',
		calendars: 2,
		mode: 'range',
		starts: 1,
		position: 'bottom',
		onChange: function(formated, dates){
			$('#slDate').val(formated);
			$('#slDate').val(formated.join(' / '));
			$('#slDate').DatePickerHide();
		}
	});
</script>